<?php

namespace app\qsapi\model;

class BoxMemberRemain extends BaseModel
{

    /**
     * 添加或更新记录
     * @param $date
     * @param $totalReg
     * @param $day
     * @param $num
     * @return void
     */
    public function addInfo($date, $totalReg, $day, $num){
        //判断当前日期是否有记录存在
        $rowId = $this->field('id')->where([['date', '=', $date]])->find();
        if (!empty($rowId)){
            //更新数据
            $data = array(
                "date" => $date,
                "reg_num" => $totalReg,
                "{$day}day" => $num
            );
            $this->update($data, ['id' => $rowId['id']]);
        } else {
            //插入数据
            $data = array(
                "date" => $date,
                "reg_num" => $totalReg,
                "{$day}day" => $num
            );
            $this->insert($data);
        }
    }

}